package com.yupi.yuapiinterface.controller;



import com.yupi.yuapiinterface.annotation.ApiAuthCheck;
import com.yupi.yuapiinterface.annotation.ApiCount;
import com.yupi.yuapiinterface.model.DTO.UserDTO;
import com.yupi.yuapiinterface.service.UserService;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletRequest;

/**
 * 名称 API
 */
@RestController
@RequestMapping("/name")
@AllArgsConstructor
public class NameController {

    private final UserService userService;

    @GetMapping("/get")
    public String getNameByGet(String name, HttpServletRequest request) {
        System.out.println(request.getHeader("yupi"));
        return "GET 你的名字是" + name;
    }

    @PostMapping("/post")
    public String getNameByPost(@RequestParam String name) {
        return "POST 你的名字是" + name;
    }

    @PostMapping("/user")
    @ApiAuthCheck(interfaceName = "获取用户名接口")  // 需要签名认证
    @ApiCount(interfaceName = "获取用户名接口",interfaceId = 21)
    public String getUsernameByPost(@RequestBody UserDTO userDto, HttpServletRequest request) {
        System.out.println("NameController.getUsernameByPost - 接收到的UserDTO: " + userDto);
        String result = userService.getUserByName(userDto,request);
        System.out.println("NameController.getUsernameByPost - 返回结果: " + result);
        return result;
    }

    @GetMapping("/test")
    public String test(HttpServletRequest request,String name) {
        System.out.println("收到请求: " + request.getRequestURI());
        System.out.println("收到请求: " + request.getHeader("name"));
        return name;
    }

}
